﻿using STHPMS1.DAL.D_Core;
using STHPMS1.ICore.I_DAL.Repository;
using System.Data;
using ServiceStack.OrmLite;
using System.Collections.Generic;

namespace STHPMS1.DAL.D_Repository
{
    public class Dr_Largemeas_IniRepository : DalBase, IDr_Largemeas_IniRepository
    {
        public void UpdateMaterils(string iniproj_Id, string hotmonth, string exetem, string annurain)
        {
            if (string.IsNullOrEmpty(hotmonth) && string.IsNullOrEmpty(exetem) && string.IsNullOrEmpty(annurain)) return;
            string sql = "update DR_LARGEMEAS_INI set ";
            if (!string.IsNullOrEmpty(hotmonth)) sql += " HOTMONTH =" +hotmonth+",";
            if (!string.IsNullOrEmpty(exetem)) sql += " EXETEM =" + exetem + ",";
            if (!string.IsNullOrEmpty(annurain)) sql += " ANNURAIN =" + annurain + ",";

            sql=sql.TrimEnd(',');
            sql += string.Format("  where INIPROJ_ID='{0}' ", iniproj_Id);

            IDbConnection conn = Adapter.OpenDbConnection();
            conn.ExecuteNonQuery(sql);
        }


        public List<string> GetMainSeg()
        {
            string sql = "SELECT MAINSEGID from DR_LARGEMEAS_INI GROUP BY MAINSEGID;";
            IDbConnection conn = Adapter.OpenDbConnection();
            return conn.SqlList<string>(sql);
        }
    }
}
